package v1

import (
	"github.com/gin-gonic/gin"
	"hytx_media/models"
	"hytx_media/service/message_service"
	"net/http"
	"hytx_media/pkg/e"
	"hytx_media/pkg/app"
	"github.com/Unknwon/com"
	"hytx_media/pkg/util"
)

func GetMessageNum(c *gin.Context) {
	ag := app.Gin{C: c}
	user := c.MustGet("user").(*models.MediaUser)
	msg := message_service.GetMsgNum(user.ID)
	ag.Response(http.StatusOK, e.SUCCESS, msg)
}

func GetMessage(c *gin.Context) {
	ag := app.Gin{C: c}
	user := c.MustGet("user").(*models.MediaUser)
	t := c.Query("type")
	page := 1
	if arg := c.Query("p"); arg != "" {
		page = com.StrTo(arg).MustInt()
	}
	var (
		msg interface{}
		paginate *util.Paginate
	)
	switch t {
	case "notice":
		msg, paginate = message_service.GetNoticeList(user.ID, page, 10)
	case "comment":
		msg, paginate = message_service.GetCommentMessageList(user.ID, page, 10)
	case "follow":
		msg, paginate = message_service.GetFollowMessageList(user.ID, page, 10)
	case "collection":
		msg, paginate = message_service.GetCollectionMessageList(user.ID, page, 10)
	case "share":
		msg, paginate = message_service.GetShareMessageList(user.ID, page, 10)
	default:
		ag.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
		return
	}
	data := make(map[string]interface{})
	data["data"] = msg
	data["total"] = paginate.Total()
	data["count"] = paginate.Count
	data["current"] = paginate.Page
	ag.Response(http.StatusOK, e.SUCCESS, data)
}
func GetNoticeContent(c *gin.Context) {
	ag := app.Gin{C: c}
	id := com.StrTo(c.Param("id")).MustInt()
	content := message_service.NoticeContent(id)
	ag.Response(http.StatusOK, e.SUCCESS, content)
}